#include "MainCounterState.h"
#include "Counter.h"
#include "HUDtimer.h"
#include "Exception.h"

using namespace game_engine::components;
using namespace game_engine::library;
using namespace game_engine::utils;

///////////////////////////////////////////////////////////////////////////////
// Constructors and Destructors
///////////////////////////////////////////////////////////////////////////////

MainCounterState::MainCounterState(void)
    : State()
{
}

MainCounterState::MainCounterState(Behaviour *parent)
    : State(parent)
{
}

MainCounterState::~MainCounterState(void)
{
}

///////////////////////////////////////////////////////////////////////////////
// Other public methods
///////////////////////////////////////////////////////////////////////////////

void MainCounterState::onLoop(const FLOAT32 time) throw(...)
{
    // Retrieve current timer value
    Counter *c = dynamic_cast<Counter*> (fsm);
    FLOAT32 val = c->getValue();

    // Update timer value according to mode
    TimerMode m = c->getMode();
    if (m == CHRONOMETER)
    {
        c->setValue(val + time);
    }
    else if (m == TIMER)
    {
        c->setValue(val - time);
    }
    else
    {
        throw RuntimeException("unknown timer mode");
    }
}
